package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.client.ProviderClient1;
import com.atguigu.springcloud.domain.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.security.Principal;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/v1")
public class MyTestController1 {

    @Autowired
    private ProviderClient1 providerClient1;

    // 服务端GET请求，没有入参
    @RequestMapping(value = "/dept/list")
    public List<Dept> list() {
        return this.providerClient1.list();
    }

    // 服务端使用GET请求，且入参是从路径上取值
    @RequestMapping(value = "/dept/get/{id}")
    public Dept get(@PathVariable("id") Long id) {
        return this.providerClient1.get(id);
    }

    // 服务端GET请求，只有一个String类型的入参
    @RequestMapping(value = "/dept/getById")
    public Dept getById(@RequestParam(value = "id") Long id){
        return this.providerClient1.getById(id);
    }

    // 服务端GET请求，有一个以上的String类型入参
    @RequestMapping(value = "/dept/getByIdAndDeptName")
    public Dept getByIdAndDeptName(@RequestParam(value = "id") Long id,
                                   @RequestParam(value = "deptName")String deptName){
        return this.providerClient1.getByIdAndDeptName(id, deptName);
    }

    // 服务端使用GET请求，且入参是一个实体类
    @RequestMapping(value = "/dept/getByDept")
    public Dept getByDept(@RequestParam Map param) {
        System.out.println("请求参数：" + param);
        return this.providerClient1.getByDept(param);
    }

    // 服务器使用POST请求，入参是一个实体类
    @RequestMapping(value = "/dept/add")
    public boolean add(@RequestBody Dept dept) {
        return this.providerClient1.add(dept);
    }

    // 服务器使用POST请求，入参是一个字符串类型，一个是实体对象类型
    @RequestMapping(value = "/dept/addWithAddress1")
    public boolean addWithAddress(@RequestParam(value = "username") String username,
                                  @RequestBody Dept dept){
        return this.providerClient1.addWithAddress1(username, dept);
    }


}
